home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / os2 / mlrxshl.zip / QUERY.CMD < prev    next >
OS/2 REXX Batch file  |  1995-12-22  |  4KB  |  111 lines

  1. /* query.cmd - compute connect time                            951222 */
  2. /* (C) Copyright Martin Lafaix 1995.  All rights reserved.            */
  3.  
  4. /* Recognized command line args
  5.  
  6.    query date
  7.    query time
  8.    query [timeframe] [detailed] connect time [for ...]
  9.    query [timeframe] [last] connect message [for ...]
  10.    
  11.    timeframe == ((this|last) (year|month)|monthname)
  12.    monthname == JANuary | FEBruary | MARch | APRil | MAY | JUNe | JULy |
  13.                 AUGust | SEPtember | OCTober | NOVember | DECember
  14.                 
  15.    examples
  16.    
  17.    query connect time
  18.    query this year connect time for user1
  19.    query detailed november connect time for user1 user2 
  20.    query last connect message
  21. */
  22.  
  23. arg user_arg
  24. parse arg request
  25.  
  26. select
  27.    when user_arg = 'DATE' then
  28.       say date()
  29.    when user_arg = 'TIME' then 
  30.       say time()
  31.    when wordpos('CONNECT',user_arg) > 0 then
  32.       say connect()
  33. otherwise
  34.    say 'Unknown request:' request
  35. end  /* select */
  36.  
  37. exit
  38.  
  39. connect:
  40.    monthname = '\JANUARY  \FEBRUARY \MARCH    \APRIL    \MAY      \JUNE     '||,
  41.                '\JULY     \AUGUST   \SEPTEMBER\OCTOBER  \NOVEMBER \DECEMBER'
  42.    detailed = wordpos('DETAILED',user_arg) > 0
  43.    msg = wordpos('MESSAGE',user_arg)+wordpos('MESSAGES',user_arg) > 0
  44.    this = wordpos('THIS',user_arg) > 0
  45.    last = wordpos('LAST',user_arg) > 0
  46.    user = wordpos('FOR',user_arg) > 0
  47.    mm = wordpos('MONTH',user_arg)+wordpos('MONTH''S',user_arg) > 0
  48.    yy = wordpos('YEAR',user_arg)+wordpos('YEAR''S',user_arg) > 0
  49.    m = 0
  50.    do i = 1 to words(user_arg)
  51.       w = pos('\'word(user_arg,i),monthname)
  52.       if w > 0 then
  53.          if abbrev(substr(monthname,w+1,9),word(user_arg,i),3) = 1 then
  54.             if m \= 0 then
  55.                return 'Incorrect request:' request
  56.             else
  57.                m = 1 + w % 10
  58.    end /* do */
  59.  
  60.    count = \user
  61.    if user then
  62.       userlist = substr(request,wordindex(user_arg,wordpos('FOR',user_arg))+4)
  63.  
  64.    if this & last | mm & yy | mm & (m > 0) then
  65.       return 'Incorrect request:' request
  66.  
  67.    log = value('ETC',,'OS2ENVIRONMENT')'\Connect.log'
  68.    time = 0
  69.    parse value date('S') with year 5 month 7 .
  70.    if last & mm then month = month-1
  71.    if last & yy then year = year-1
  72.    if yy then month = ''
  73.    if m \= 0 then month = m
  74.    yymm = year'/'month
  75.  
  76.    message = ''
  77.    curLine = 1
  78.    do while lines(log) \= 0
  79.       line=linein(log); curLine = curLine+1
  80.       if left(line,length(yymm)) = yymm then do
  81.          if substr(line,21,1) = '─' then beginning = curLine
  82.          if count & msg & curLine > beginning+2 & substr(line,21,18) <> 'Disconnected after' then
  83.             if last & curLine = beginning+3 then
  84.                message = line
  85.             else
  86.                message = message || copies('0d0a'x,1+(curLine = beginning+3)) || line
  87.          else
  88.          if user & word(line,5) = 'dialed' then 
  89.             count = wordpos(word(line,4),userlist) > 0
  90.          else
  91.          if count & substr(line,21,18) = 'Disconnected after' then
  92.             call sum word(line,5), line
  93.          end
  94.    end
  95.  
  96.    call stream log, 'c', 'close'
  97.  
  98.    if msg then
  99.       return message
  100.    else
  101.    if yy then
  102.       return year 'Yearly connect time' (time % 3600)':' || right((time // 3600) % 60,2,0) || ':' || right(time // 60,2,0)
  103.    else
  104.       return year'/'right(month,2,0) 'Monthly connect time' (time % 3600)':' || right((time // 3600) % 60,2,0) || ':' || right(time // 60,2,0)
  105.  
  106. sum:
  107.    parse value arg(1) with h ':' m ':' s
  108.    if detailed then say word(arg(2),1) arg(1)
  109.    time = time + s + 60 * m + 3600 * h
  110.    return
  111.